//
//  ProductListTableViewCell.m
//  OutesIOS
//
//  Created by norman on 2019/1/29.
//  Copyright © 2019 norman. All rights reserved.
//

#import "ProductListTableViewCell.h"
#import "UITapView.h"

@interface ProductListTableViewCell()

@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIImageView *selectImg;
@property (nonatomic,strong)UITapView *infoView;

@end

@implementation ProductListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

/**
 *  <#Description#>
 */
- (void)setupViews {
    self.contentView.width = kScreen_Width;
    
    self.selectImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"product_select"]];
    self.selectImg.x = 5;
    [self.contentView addSubview:self.selectImg];
    
    UIImageView *info = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"product_info"]];
    
    info.x = 10;
    self.infoView = [[UITapView alloc]initWithFrame:CGRectMake(0, 0, info.width + 20, 0)];
    @weakObj(self);
    [self.infoView addTargetsBlock:^(id obj) {
        if (Weakself.viewInfo != nil) {
            Weakself.viewInfo();
        }
    }];
    self.infoView.x = kScreen_Width - self.infoView.width;
    [self.infoView addSubview:info];
    [self.contentView addSubview:self.infoView];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.selectImg.frame) + 2, CELL_PADDING_TOP, self.infoView.x - CGRectGetMaxX(self.selectImg.frame) - 5, kListTitleFontSize)];
    self.titleLabel.font = [UIFont systemFontOfSize:kListTitleFontSize];
    self.titleLabel.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.titleLabel];
    
    self.contentView.height = CGRectGetMaxY(self.titleLabel.frame) + CELL_PADDING_TOP;
    self.infoView.height = self.contentView.height;
    self.selectImg.centerY = self.contentView.height/2;
    info.centerY = self.contentView.height/2;
}

- (void)setTitle:(NSString*)title andSelectState:(BOOL)select {
    self.selectImg.hidden = !select;
    self.titleLabel.text = title;
}

- (CGFloat)cellHeight {
    return self.contentView.height;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
